﻿Public Class BlockFiveHomeworkSectionOne
    Dim QuestionNumber As Integer
    Dim dtmTest, dtmTest2 As Date
    Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
    'Declare the Array as 10 rows and 3 columns
    Dim ArrayMax As Integer = 30 'One number past the end of actual info in array
    Dim HWQuestions(ArrayMax, 7) As String
    Dim intResponse As Integer
    Dim intQuestionCount As Integer = 0
    Dim intAnswerCount As Integer = 0
    Dim intReferenceCount As Integer = 0
    Dim intFirstRun As Integer = 1
    Dim strUser As String = "Enter Last Name"
    Dim strAnswer, strAnswer2, strAnswer3, strAnswer4, strAnswer5, _
     strAnswer6, strAnswer7, strAnswer8, strAnswer9, strAnswer10, strAnswer11, _
     strAnswer12, strAnswer13, strAnswer14, strAnswer15, strAnswer16, _
     strAnswer17, strAnswer18, strAnswer19, strAnswer20, strAnswer21, _
     strAnswer22, strAnswer23, strAnswer24, strAnswer25, strAnswer26, _
     strAnswer27, strAnswer28, strAnswer29 As String
    Dim intChoiceACount As Integer = 2
    Dim intChoiceBCount As Integer = 3
    Dim intChoiceCCount As Integer = 4
    Dim intChoiceDCount As Integer = 5

    Shared Property MidiParent As MainForm

    Private Sub CloseToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles CloseToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub BlockTwoHomeworkSectionOne_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        txtObj.Text = "Objectives:" + vbCrLf + "- Given proper student instructional materials, identify a fixed ATC Ground-to-Air system." _
                                    + vbCrLf + "- Given proper student instructional materials, identify headset operating principles." _
                                    + vbCrLf + "- Given proper student instructional materials, identify Telephone Principles associated with an ATC Ground-to-Air system." _
                                    + vbCrLf + "- Given proper student instructional materials, describe Digital Audio and Time Division Multiplexing (TDM) principles."
        If (System.IO.File.Exists(filename & "\Homework\Block 5\Block 5 Section 1.txt")) Then
            intResponse = MsgBox("This assignment has already been completed.  Are you sure you want to delete the current assignment and reaccomplish it?", 4, "Confirm Assignment Deletion")
            If intResponse = MsgBoxResult.Yes Then
                System.IO.File.Delete(filename & "\Homework\Block 5\Block 5 Section 1.txt")
                System.IO.File.Create(filename & "\Homework\Block 5\Block 5 Section 1.txt").Dispose()
            ElseIf intResponse = MsgBoxResult.No Then
                Me.Close()
            End If
        End If
        If (Not System.IO.File.Exists(filename & "\Homework\Block 5\Block 5 Section 1.txt")) Then
            System.IO.File.Create(filename & "\Homework\Block 5\Block 5 Section 1.txt").Dispose()
        End If
        If (Not System.IO.File.Exists(filename & "\Instructor\Block 5\Block 5 Section 1.txt")) Then
            System.IO.File.Create(filename & "\Instructor\Block 5\Block 5 Section 1.txt").Dispose()
        End If
        strUser = InputBox("Please enter last name", strUser)
        If strUser Is "" Then
            Me.Close()
        End If
        lblChoiceA.Visible = False
        txtChoiceA.Visible = False
        chkboxChoiceA.Visible = False
        lblChoiceB.Visible = False
        txtChoiceB.Visible = False
        chkboxChoiceB.Visible = False
        lblChoiceC.Visible = False
        txtChoiceC.Visible = False
        chkboxChoiceC.Visible = False
        lblChoiceD.Visible = False
        txtChoiceD.Visible = False
        chkboxChoiceD.Visible = False
        '************************************************
        '****** Questions Are Loaded Here****************
        '******* Column 1 is Questions (Preloaded)*******
        '******* Column 2 is Accepts Students Answer*****
        '******* Column 3 is Reference ******************

        HWQuestions(1, 1) = “1. What is the function of the coordinator position?”
        HWQuestions(1, 2) = strAnswer
        HWQuestions(1, 3) = "Reference"

        HWQuestions(2, 1) = "2. After RF is converted to AF, how is it sent to the tower facility?"
        HWQuestions(2, 2) = strAnswer2
        HWQuestions(2, 3) = "Reference"

        HWQuestions(3, 1) = "3. Who is ultimately responsible for tower operations?"
        HWQuestions(3, 2) = strAnswer3
        HWQuestions(3, 3) = "Reference"

        HWQuestions(4, 1) = "4. Where is the central equipment normally located?"
        HWQuestions(4, 2) = strAnswer4
        HWQuestions(4, 3) = "Reference"

        HWQuestions(5, 1) = "1. Name the transducer that changes sound energy into electrical energy?"
        HWQuestions(5, 2) = strAnswer5
        HWQuestions(5, 3) = "Reference"

        HWQuestions(6, 1) = "2. Which type of microphone requires an external power source?"
        HWQuestions(6, 2) = strAnswer6
        HWQuestions(6, 3) = "Reference"

        HWQuestions(7, 1) = "3. What device converts electrical energy into sound energy?"
        HWQuestions(7, 2) = strAnswer7
        HWQuestions(7, 3) = "Reference"

        HWQuestions(8, 1) = "4. What does the term 'frequency response' indicate?"
        HWQuestions(8, 2) = strAnswer8
        HWQuestions(8, 3) = "Reference"

        HWQuestions(9, 1) = "6. What is the purpose of a midrange speaker?"
        HWQuestions(9, 2) = strAnswer9
        HWQuestions(9, 3) = "Reference"

        HWQuestions(10, 1) = "7. What causes the voice coil of a permanent magnet speaker to move back and forth?"
        HWQuestions(10, 2) = strAnswer10
        HWQuestions(10, 3) = "Reference"

        HWQuestions(11, 1) = "1. What component connects and disconnects your phone from the network?"
        HWQuestions(11, 2) = "hook switch"
        HWQuestions(11, 4) = "duplex switch"
        HWQuestions(11, 5) = "network switch"
        HWQuestions(11, 6) = "disconnect"
        HWQuestions(11, 3) = "Reference"

        HWQuestions(12, 1) = "2. When you lift the handset, __________ flows between the phone and the central office."
        HWQuestions(12, 2) = strAnswer12
        HWQuestions(12, 3) = "Reference"

        HWQuestions(13, 1) = "3. The telephone provider senses the completion of the loop and plays a __________ so you know your phone is working. ?"
        HWQuestions(13, 2) = strAnswer13
        HWQuestions(13, 3) = "Reference"

        HWQuestions(14, 1) = "4. When you speak into the microphone, ______________ modulate the current. "
        HWQuestions(14, 2) = "voice nodules"
        HWQuestions(14, 4) = "speaker crystals"
        HWQuestions(14, 5) = "carbon granules"
        HWQuestions(14, 6) = "line card voltages"
        HWQuestions(14, 3) = "Reference"

        HWQuestions(15, 1) = "5. PBX circuits are most likely ______ lines."
        HWQuestions(15, 2) = strAnswer15
        HWQuestions(15, 3) = "Reference"


        HWQuestions(16, 1) = "6. An ASU is sometimes referred to as a __________ circuit."
        HWQuestions(16, 2) = "Hot Line"
        HWQuestions(16, 4) = "Ring Out"
        HWQuestions(16, 5) = "Ring Down"
        HWQuestions(16, 6) = "All the Above"
        HWQuestions(16, 3) = "Reference"

        HWQuestions(17, 1) = "7. Selective Signaling lines connect one air traffic control facility to another.."
        HWQuestions(17, 2) = "True"
        HWQuestions(17, 4) = "False"
        HWQuestions(17, 5) = ""
        HWQuestions(17, 6) = ""
        HWQuestions(17, 3) = "Reference"

        HWQuestions(18, 1) = "8. What is the primary signaling method employed by the SS-1/SS-4?"
        HWQuestions(18, 2) = "SF"
        HWQuestions(18, 4) = "FSK"
        HWQuestions(18, 5) = "DIAL"
        HWQuestions(18, 6) = "DTMF"
        HWQuestions(18, 3) = "Reference"

        HWQuestions(18, 1) = "9. E&M circuits are called 'universal' because they can be configured for _______________ ?"
        HWQuestions(18, 2) = "Different Sites"
        HWQuestions(18, 4) = "Different Locations"
        HWQuestions(18, 5) = "Different Impedances"
        HWQuestions(18, 6) = "Different Applications"
        HWQuestions(18, 3) = "Reference"

        HWQuestions(19, 1) = "10. Only ______ wires are used when the E&M is configured as a voice line?"
        HWQuestions(19, 2) = strAnswer19
        HWQuestions(19, 3) = "Reference"

        HWQuestions(20, 1) = "1. A telecommunications CODEC will output a/an ________ bit digital word each time it samples the input audio signal.?"
        HWQuestions(20, 2) = strAnswer20
        HWQuestions(20, 3) = "Reference"

        HWQuestions(21, 1) = "2. For telecommunications devices, the sampling rate will be __________ times per second.?"
        HWQuestions(21, 2) = strAnswer21
        HWQuestions(21, 3) = "Reference"

        HWQuestions(22, 1) = "3. What is the highest frequency we should expect a telecommunications CODEC to convert into digital audio and then back again?"
        HWQuestions(22, 2) = "2 kHz"
        HWQuestions(22, 4) = "4 kHz"
        HWQuestions(22, 5) = "6 kHz"
        HWQuestions(22, 6) = "8 kHz"
        HWQuestions(22, 3) = "Reference"

        HWQuestions(23, 1) = "4. A telecommunications CODEC uses _________ discrete levels to represent an analog signal."
        HWQuestions(23, 2) = strAnswer23
        HWQuestions(23, 3) = "Reference"

        HWQuestions(24, 1) = "5. The process of determining which discrete level correctly represents the amplitude of the input signal is referred to as ______________."
        HWQuestions(24, 2) = strAnswer24
        HWQuestions(24, 3) = "Reference"

        HWQuestions(25, 1) = "6. In Time Division Multiplexing, each digital audio channel is assigned a specific _______________."
        HWQuestions(25, 2) = "time slot"
        HWQuestions(25, 4) = "frequency"
        HWQuestions(25, 5) = "pulse width"
        HWQuestions(25, 6) = "carrier amplitude"
        HWQuestions(25, 3) = "Reference"

        HWQuestions(26, 1) = "7. All data for all channels will be placed on the digital audio bus every 125 μ seconds."
        HWQuestions(26, 2) = "True"
        HWQuestions(26, 4) = "False"
        HWQuestions(26, 5) = ""
        HWQuestions(26, 6) = ""
        HWQuestions(26, 3) = "Reference"

        HWQuestions(27, 1) = "8. By combining 32 digital channels onto a single ST bus, the resulting data stream will be ________ Mbits/second."
        HWQuestions(27, 2) = strAnswer27
        HWQuestions(27, 3) = "Reference"

        HWQuestions(28, 1) = "9.Which bus type protocol is referred to as CETP-1?"
        HWQuestions(28, 2) = "C1"
        HWQuestions(28, 4) = "E1"
        HWQuestions(28, 5) = "S1"
        HWQuestions(28, 6) = "T1"
        HWQuestions(28, 3) = "Reference"

        HWQuestions(29, 1) = "10. The SNIC converts a 64 Kbit/sec digital audio stream from ISDN protocol to _____ protocol."
        HWQuestions(29, 2) = strAnswer29
        HWQuestions(29, 3) = "Reference"

        HWQuestions(30, 1) = "Close"

        Next_Question(HWQuestions)
    End Sub

    Private Sub btnNextQuestion_Click(sender As System.Object, e As System.EventArgs) Handles btnNextQuestion.Click
        Next_Question(HWQuestions)
    End Sub
    Private Sub Clear_Display()
        txtQuestion.Clear()
        txtAnswer.Clear()
    End Sub

    Public Function Next_Question(HWQuestions As String(,))
        txtAnswer.Focus()
        If intQuestionCount > 0 Then
            WriteToFile()
        End If
        If btnNextQuestion.Text = "Done" Then
            Me.Close()
            OpenResults()
        End If
        intQuestionCount = intQuestionCount + 1
        LabelChangeCheck()
        If intQuestionCount = 29 Then
            btnNextQuestion.Text = "Done"
        End If
        If intQuestionCount = 11 Or intQuestionCount = 14 Or intQuestionCount = 16 _
            Or intQuestionCount = 18 Or intQuestionCount = 22 Or intQuestionCount = 25 _
            Or intQuestionCount = 28 Then
            lblChoiceA.Visible = True
            txtChoiceA.Visible = True
            chkboxChoiceA.Visible = True
            lblChoiceB.Visible = True
            txtChoiceB.Visible = True
            chkboxChoiceB.Visible = True
            lblChoiceC.Visible = True
            txtChoiceC.Visible = True
            chkboxChoiceC.Visible = True
            lblChoiceD.Visible = True
            txtChoiceD.Visible = True
            chkboxChoiceD.Visible = True
            lblAnswer.Visible = False
            txtAnswer.Visible = False

            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            txtChoiceA.Text = HWQuestions(intQuestionCount, 2)
            txtChoiceB.Text = HWQuestions(intQuestionCount, 4)
            txtChoiceC.Text = HWQuestions(intQuestionCount, 5)
            txtChoiceD.Text = HWQuestions(intQuestionCount, 6)

        ElseIf intQuestionCount = 1 Or intQuestionCount = 2 Or intQuestionCount = 3 _
            Or intQuestionCount = 4 Or intQuestionCount = 5 Or intQuestionCount = 6 _
            Or intQuestionCount = 7 Or intQuestionCount = 8 Or intQuestionCount = 9 _
            Or intQuestionCount = 10 Or intQuestionCount = 12 Or intQuestionCount = 13 _
            Or intQuestionCount = 15 Or intQuestionCount = 17 Or intQuestionCount = 19 _
            Or intQuestionCount = 20 Or intQuestionCount = 21 Or intQuestionCount = 23 _
            Or intQuestionCount = 24 Or intQuestionCount = 26 Or intQuestionCount = 27 Or intQuestionCount = 29 Then
            lblChoiceA.Visible = False
            txtChoiceA.Visible = False
            chkboxChoiceA.Visible = False
            lblChoiceB.Visible = False
            txtChoiceB.Visible = False
            chkboxChoiceB.Visible = False
            lblChoiceC.Visible = False
            txtChoiceC.Visible = False
            chkboxChoiceC.Visible = False
            lblChoiceD.Visible = False
            txtChoiceD.Visible = False
            chkboxChoiceD.Visible = False
            lblAnswer.Visible = True
            txtAnswer.Visible = True
            txtQuestion.Text = HWQuestions(intQuestionCount, 1)
            intAnswerCount = intAnswerCount + 1
            HWQuestions(intAnswerCount, 2) = txtAnswer.Text
            intReferenceCount = intReferenceCount + 1
            txtReference.Text = HWQuestions(intReferenceCount, 3)
        End If
        Return intQuestionCount & intAnswerCount
    End Function

    Private Sub LabelChangeCheck()
        If intQuestionCount = 1 Then
            lblSubject.Text = "ATC Systems"
        ElseIf intQuestionCount = 5 Then
            lblSubject.Text = "Microphones and Speakers"
        ElseIf intQuestionCount = 11 Then
            lblSubject.Text = "How telephones work"
        ElseIf intQuestionCount = 20 Then
            lblSubject.Text = "Digital Audio Principles"
        End If
    End Sub

    Private Sub WriteToFile()
        Dim Integrity As String = (filename & "\Instructor\Block 5\Block 5 Section 1.txt")
        Dim Results As String = (filename & "\Homework\Block 5\Block 5 Section 1.txt")

        '***********Output to hidden file for Instructor Check***********
        If System.IO.File.Exists(Integrity) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Integrity, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine("- " & txtObj.Text)
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
            hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
            hiddenWriter.WriteLine("Reference: " & txtReference.Text)
            hiddenWriter.WriteLine()
            If intQuestionCount = 29 Then
                hiddenWriter.WriteLine("Block 5 Section 1 Homework Complete")
                hiddenWriter.WriteLine("Date: " & (DateValue(Now)))
                hiddenWriter.WriteLine("Time: " & (TimeValue(Now)))
            End If
            hiddenWriter.Close()

            'MsgBox("Text written to file")
        Else
            MsgBox("File Does Not Exist Integrity")
        End If

        '******Output to file for Student to review***********
        If System.IO.File.Exists(Results) = True Then
            Dim hiddenWriter As New System.IO.StreamWriter(Results, True)
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine()
                hiddenWriter.WriteLine("Student: " & strUser)
            End If
            If intQuestionCount = 1 Then
                hiddenWriter.WriteLine(lblSubject.Text)
            ElseIf intQuestionCount = 5 Then
                hiddenWriter.WriteLine(lblSubject.Text)
            ElseIf intQuestionCount = 11 Then
                hiddenWriter.WriteLine(lblSubject.Text)
            ElseIf intQuestionCount = 20 Then
                hiddenWriter.WriteLine(lblSubject.Text)
            End If
            hiddenWriter.WriteLine("Question:" & txtQuestion.Text)
            If intQuestionCount = 11 Or intQuestionCount = 14 Or intQuestionCount = 16 _
                    Or intQuestionCount = 18 Or intQuestionCount = 22 Or intQuestionCount = 25 _
                    Or intQuestionCount = 28 Then
                If chkboxChoiceA.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  A: " & txtChoiceA.Text)
                ElseIf chkboxChoiceB.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  B: " & txtChoiceB.Text)
                ElseIf chkboxChoiceC.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  C: " & txtChoiceC.Text)
                ElseIf chkboxChoiceD.CheckState = 1 Then
                    hiddenWriter.WriteLine("Answer:  D: " & txtChoiceD.Text)
                End If
            End If
            If intQuestionCount = 1 Or intQuestionCount = 2 Or intQuestionCount = 3 _
            Or intQuestionCount = 4 Or intQuestionCount = 5 Or intQuestionCount = 6 _
            Or intQuestionCount = 7 Or intQuestionCount = 8 Or intQuestionCount = 9 _
            Or intQuestionCount = 10 Or intQuestionCount = 12 Or intQuestionCount = 13 _
            Or intQuestionCount = 15 Or intQuestionCount = 17 Or intQuestionCount = 19 _
            Or intQuestionCount = 20 Or intQuestionCount = 21 Or intQuestionCount = 23 _
            Or intQuestionCount = 24 Or intQuestionCount = 26 Or intQuestionCount = 27 Or intQuestionCount = 29 Then
                hiddenWriter.WriteLine("Answer:" & txtAnswer.Text)
                'hiddenWriter.WriteLine("Reference: " & txtReference.Text)
            End If
            hiddenWriter.WriteLine()
            If intQuestionCount = 29 Then
                hiddenWriter.WriteLine("Block 5 Section 1 Homework Complete")
            End If
            hiddenWriter.Close()
        Else
            MsgBox("File Does Not Exist Results")
        End If

        If intQuestionCount > 0 Then
            txtAnswer.Clear()
            chkboxChoiceA.CheckState = CheckState.Unchecked
            chkboxChoiceB.CheckState = CheckState.Unchecked
            chkboxChoiceC.CheckState = CheckState.Unchecked
            chkboxChoiceD.CheckState = CheckState.Unchecked
        End If

    End Sub

    Private Sub OpenResults()
        Dim p As Process = Process.Start(filename & "\Homework\Block 5\Block 5 Section 1.txt")
    End Sub
End Class
